import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/model/hand_over/hand_over_model.dart';

import '../../a_yyt/models/handover_new_entity.dart';
class NewHandOverHomeViewModel extends BaseListViewModel<HandoverNewInfo>{
  NewHandOverHomeViewModel(super.context);

  var model = HandOverModel();

  dynamic queryType = 0;

  DateTime? chooseTime;

  String get chooseTimeStr => chooseTime==null?"":chooseTime!.toDateStr(["yyyy",'-','mm']);

  @override
  Future<List<HandoverNewInfo>> requestListData() async {
    return await model.handOverList(queryType);
  }

  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }

  void chooseQueryType(dynamic query){
    if(this.queryType!=query){
      if(query==0||query==1){
        this.queryType = query;
        requestRefresh();
      }else{
       queryType = chooseTime==null?query: chooseTime!.toDateStr(['yyyy','mm']);
       if(queryType!=null){
         requestRefresh();
       }
      }

      notifyListeners();
    }

  }

  void chooseQueryTime(){
    DatePicker.showMonthPicker(context,currentTime: chooseTime,onConfirm: (date){
      chooseTime = date;
      queryType = date!.toDateStr(['yyyy','mm']);
      notifyListeners();
      requestRefresh();
    });
  }

}